package com.fjh.module.rbac.service.impl;

import java.io.IOException;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import com.fjh.common.constant.Constants;
import com.fjh.common.manager.AsyncManager;
import com.fjh.common.manager.factory.AsyncFactory;
import com.fjh.security.easy.starter.authentication.service.EasyAuthFailureService;
import com.fjh.security.easy.starter.authentication.service.impl.EasyDefaultAuthFailureServiceImpl;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Service;

/**
 * @author fanjh37
 */
@Service
public class EasyAuthFailureServiceImpl extends EasyDefaultAuthFailureServiceImpl {


    @Override
    public void authenticationFailure(HttpServletRequest httpServletRequest,
        HttpServletResponse httpServletResponse, AuthenticationException e)
        throws IOException, ServletException {
        super.authenticationFailure(httpServletRequest, httpServletResponse, e);
        String username = (String) httpServletRequest.getAttribute("username");
        AsyncManager.me().execute(
            AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL,
                e.getMessage()));
    }
}
